--殡殓莲眠
local bingjianlianmian = fk.CreateSkill {
    name = "mcdh_bingjianlianmian",
    tags = {Skill.Limited}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

bingjianlianmian:addEffect(fk.EnterDying,{
    can_trigger = function(self, event, target, player, data)
        if target:getMark("@mcdh_yizang") == 0 then
            return player:hasSkill(self)  and player:usedSkillTimes(self.name,Player.HistoryGame) == 0
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:recover {
            who = target,
            num = 1 - target.hp,
            recoverBy = player,
            skillName = self.name,
        }
        room:setPlayerMark(target,"@mcdh_yizang",1)
        data.extra_data = data.extra_data or {}
        data.extra_data.bingjianlianmian = true
    end
})

bingjianlianmian:addEffect(fk.EnterDying,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill("mcdh_bingjianlianmian") and target:getMark("@mcdh_yizang") ~= 0 and not target.dead and data.extra_data and data.extra_data.bingjianlianmian
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:killPlayer({who = target.id})
    end
})

bingjianlianmian:addEffect(fk.AfterDrawPileShuffle,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill("mcdh_bingjianlianmian")
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:setSkillUseHistory("mcdh_bingjianlianmian",0,Player.HistoryGame)
        if room:askForSkillInvoke(player, self.name, nil, "#bingjianlianmian_tirrger") then
            for _, p in ipairs(room:getAlivePlayers()) do
                room:setPlayerMark(p,"@mcdh_yizang",0)
            end
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_bingjianlianmian"] = "殡殓莲眠",
    [":mcdh_bingjianlianmian"] = "限定技。当一名角色进入濒死状态时，你可以令其获得「仪葬」标记并回复体力至1点。有「仪葬」的角色进入濒死状态时立即死亡。（牌堆切洗后，复原本技能，且你可以移去所有角色的「仪葬」标记）",
    ["#bingjianlianmian_tirrger"] = "殡殓莲眠：移去所有角色的「仪葬」标记",
    ["@mcdh_yizang"] = "仪葬",
}

return bingjianlianmian